using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Wips.Domain.Models.Authorities.Model;

/// <summary>
/// 角色
/// </summary>
[Table("AuthorityRoles")]
[SugarTable("AuthorityRoles")]
public class Role : EntityBase, IAggregateRoot
{

    /// <summary>
    /// 名称
    /// </summary>
    [Required]
    [MaxLength(32)]
    public string Name { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    [MaxLength(500)]
    public string Remarks { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public Status Status { get; set; }


    /// <summary>
    /// 角色类型
    /// </summary>
    public EnumRoleType? RoleType { get; set; } = EnumRoleType.Normal;


    /// <summary>
    /// 最后更新人Id
    /// </summary>
    public string LastUpdatedUserId { get; set; }



    public Role()
    {
    }


    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="remarks"></param>
    /// <param name="creatorId"></param>
    public Role(string name, string remarks, string creatorId)
    {
        Name = name;
        Remarks = remarks;
        CreatorId = creatorId;
        RoleType = EnumRoleType.Normal;
    }

    /// <summary>
    /// 状态变更
    /// </summary>
    /// <param name="lastUpdatedUserId"></param>
    public void StatusChange(string lastUpdatedUserId)
    {
        Status = Status == Status.Disabled ? Status.Enabled : Status.Disabled;
        LastUpdatedUserId = lastUpdatedUserId;
        Updated = DateTime.Now;
    }

    /// <summary>
    /// 分配权限
    /// </summary>
    /// <param name="lastUpdatedUserId"></param>
    public void AssignPermissions(string lastUpdatedUserId)
    {
        LastUpdatedUserId = lastUpdatedUserId;
        Updated = DateTime.Now;

        // 添加领域事件
        //AddDomainEvent(new RolePermissionAssignedEvent(Id));
    }
}

public enum EnumRoleType
{
    /// <summary>
    /// 普通角色
    /// </summary>
    Normal = 0,

    /// <summary>
    /// 管理员角色
    /// </summary>
    Admin = 1,

    /// <summary>
    /// root角色
    /// </summary>
    Root = 2
}